package xcmg.device.service.threeGuaranteesPur;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xcmg.device.dao.entity.threeGuaranteesPur.ThreeGuaranteesPurExtendDO;
import xcmg.device.dao.mapper.threeGuaranteesPur.ThreeGuranteesPurExtendMapper;
import xcmg.device.util.ToolRandom;
import xcmg.device.util.ToolTime;

@Service
public class ThreeGuaranteesPurExtendService {
	@Autowired
	private ThreeGuranteesPurExtendMapper threeGuranteesPurExtendMapper;
	public boolean saveOrUpdate( ThreeGuaranteesPurExtendDO ext ){
		if (null == ext){
			return false;
		}
		String puId = ext.getPuId();
		if(StringUtils.isEmpty(puId)){
			return false;
		}
		ThreeGuaranteesPurExtendDO old = threeGuranteesPurExtendMapper.selectByPuId(puId);
		if (null == old){
			String id = getPkString();
			ext.setId(id);
			return threeGuranteesPurExtendMapper.insert(ext) > 0;
		}else{
			old.setCarNo( ext.getCarNo() );
			old.setCrmCode( ext.getCrmCode() );
			old.setPuId( ext.getPuId() );
			old.setPurchaseNo( ext.getPurchaseNo() );
			old.setSparepartCode(ext.getSparepartCode());
			old.setSparepartName(ext.getSparepartName());
			return threeGuranteesPurExtendMapper.updateSelective(ext) > 0;
		}
	}

	protected String getPkString()
	{
		return ToolTime.getNowStringByAllTime() + ToolRandom.getStringByLen( 6 ).toUpperCase();
	}
}
